import math

def generate_files(n, k,path):
    if not (0 < k < 1):
        raise ValueError("交集率 k 必须在 0 到 1 之间（不包含 0 和 1）")

    total_elements = 2 ** n
    intersection_count = int(total_elements * k)
    unique_count = total_elements - intersection_count

    # 生成文件 A：1 到 2^n
    with open(path+"a.txt", "w") as file_a:
        for i in range(1, total_elements + 1):
            file_a.write(f"{i}\n")

    # 生成文件 B
    with open(path+"b.txt", "w") as file_b:
        for i in range(unique_count + 1, total_elements + unique_count + 1):
            file_b.write(f"{i}\n")

    print(f"文件生成完成：a.txt 和 b.txt")
    print(f"每个文件包含 {total_elements} 个元素，交集率为 {k:.2f}。")

if __name__ == "__main__":
    num=16
    k=0.4
    path="./data/"+str(num)+"/"
    generate_files(num, k,path)